<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['diy']=$this->plugin_setting('diy');
$basic=$this->plugin_setting('basic');
$return['banner']=$basic['image'];
$return['basic']=$basic;
if($_RQ['op']=='main'){
	$reply=pdo_get('jy_xiuvote_reply',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	$reply['downtime']=model('jy_xiuvote/model')->date($reply['endtime']-TIMESTAMP);
	$reply['onlinetime']=json_decode($reply['onlinetime'],true);
	if($reply['is_linetime']){
		$day=date('Y-m-d',time());
		$start=strtotime($day.' '.$reply['onlinetime']['start']);
		$end=strtotime($day.' '.$reply['onlinetime']['end']);
		if($end<time()){
			$return['isout_onlinetime']=1;
		}
		if($start>time()){
			$return['isout_onlinetime']=1;
		}
		$return['novotetitle']='当前时间段不能投票,投票时间段：'.$reply['onlinetime']['start'].'~'.$reply['onlinetime']['end'];
	}
	$footernav=array(
		array('title'=>'首页','icon'=>'icon-shouye','action'=>'jy_xiuvote/index/'),
		array('title'=>'报名参加','icon'=>'icon-bianji','action'=>'jy_xiuvote/upopus/'),
		array('title'=>'排行榜','icon'=>'icon-fenlei2','action'=>'jy_xiuvote/o_list/'),
	);
	$reply['footernav']=json_decode($reply['footernav'],true);
	$reply['footernav']=$reply['footernav']?:$footernav;
	$return['reply']=$reply;
	$params['rid']=$reply['id'];
	$return['sum']=pdo_count('jy_xiuvote_opus',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'isshow'=>1),'id');
	set_html('title','活动排名');
	$return['sharedata']=array(
		'title'=>'活动排名-'.$reply['title'],
		'desc'=>'活动排名-'.$reply['infomsg'],
		'link'=>custom_url('jy_xiuvote/o_list/',true),
		'imgUrl'=>ATTACHMENT_URL.$reply['thumb'],
	);
	exi($return);
}
if($_RQ['op']=='o_detail'){
	if(!$_RQ['id']){
		exi('没有找到该作品，请重新选择！','error');
	}
	$opus=pdo_get('jy_xiuvote_opus',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	//进入作品详情，记录访问者浏览信息
	$islook=pdo_get('jy_xiuvote_looklist',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	if(empty($islook)){
		$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'oid'=>$_RQ['id'],
			'mid'=>$_SESSION['uid'],
			'createtime'=>TIMESTAMP
		
		);
		pdo_insert('jy_xiuvote_looklist',$insert);
	}
	$opus['createtime']=date('Y-m-d H:i:s',$opus['createtime']);
	$return['opus']=$opus;
	exi($return);
}
if($_RQ['op']=='like'){
	
	if(!$_RQ['id']){
		exi('没有找到该作品，请重新选择！','error');
	}
	$like=$_RQ['like'];
	$opus=pdo_get('jy_xiuvote_opus',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	if($like==1){
		pdo_update('jy_xiuvote_opus',array('like'=>$opus['like']+1),array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
		pdo_update('jy_xiuvote_looklist',array('islike'=>1),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
		
	}else{
		pdo_update('jy_xiuvote_opus',array('like'=>$opus['like']-1),array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
		pdo_update('jy_xiuvote_looklist',array('islike'=>0),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	}
	

}	
